//
//  TSJournalTabBarController.m
//  chart
//
//  Created by xu on 15/9/12.
//  Copyright (c) 2015年 xu. All rights reserved.
//

#import "TSJournalTabBarController.h"
#import "TSUserViewController.h"
#import "TSSectionListViewController.h"
#import "TSTaskSearchViewController.h"

@implementation TSJournalTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    TSUserViewController *user_vc = [[TSUserViewController alloc] init];
    user_vc.isJournal = YES;
    TSBaseNavigationController *nav_vc_journal = [[TSBaseNavigationController alloc] initWithRootViewController:user_vc];
    
    TSSectionListViewController *section_vc = [[TSSectionListViewController alloc] init];
    section_vc.isJournal = YES;
    TSBaseNavigationController *nav_vc_section = [[TSBaseNavigationController alloc] initWithRootViewController:section_vc];
    
    TSTaskSearchViewController *task_search_vc = [[TSTaskSearchViewController alloc] init];
    task_search_vc.isJournal = YES;
    TSBaseNavigationController *nav_vc_task_search = [[TSBaseNavigationController alloc] initWithRootViewController:task_search_vc];
    
    
    self.viewControllers = @[nav_vc_journal, nav_vc_section, nav_vc_task_search];
    
    NSArray *tabBarTitle = @[@"个人日程", @"部门列表", @"日程查询"];
    for (NSUInteger i = 0; i < self.viewControllers.count; i++) {
        UIViewController *viewController = [self.viewControllers objectAtIndex:i];
        if ([viewController isMemberOfClass:[UINavigationController class]]) {
            viewController = [[(UINavigationController *)viewController viewControllers] firstObject];
        }
        
        if (i == 0) {
            viewController.tabBarItem = [self tabBarItemWithImage:[NSString stringWithFormat:@"nav_nor_%zd", 3] SelectedImgName:[NSString stringWithFormat:@"nav_hlr_%zd", 3]];
        }
        else{
            viewController.tabBarItem = [self tabBarItemWithImage:[NSString stringWithFormat:@"nav_nor_%zd", i] SelectedImgName:[NSString stringWithFormat:@"nav_hlr_%zd", i]];
        }
        
        viewController.tabBarItem.tag = i;
        viewController.tabBarItem.title = tabBarTitle[i];
    }
}

#pragma mark-- tabBarItemImage
- (UITabBarItem *)tabBarItemWithImage:(NSString *)imageName SelectedImgName:(NSString *)selectedImgName {
    UIImage *norImage = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *selImage = [[UIImage imageNamed:selectedImgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:nil image:norImage selectedImage:selImage];
    
    return item;
}

@end
